package com.atguigu.controller;

import com.atguigu.model.process.ProcessType;
import com.atguigu.result.Result;
import com.atguigu.service.OaProcessTypeService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "审批模板管理")
@RestController
@RequestMapping("/admin/process/processType")
public class OaProcessTypeController {
    @Autowired
    private OaProcessTypeService oaProcessTypeService;
    @ApiOperation("获取分页列表")
    @GetMapping("{page}/{limit}")
    public Result getPage(@PathVariable Integer page,@PathVariable Integer limit){
        IPage<ProcessType> page1=new Page<>(page,limit);
        IPage<ProcessType> typeIPage = oaProcessTypeService.page(page1);
        return Result.ok(typeIPage);
    }
    @ApiOperation("根据id获取")
    @GetMapping("get/{id}")
    public Result getById(@PathVariable Integer id){
        ProcessType processType = oaProcessTypeService.getById(id);
        return Result.ok(processType);
    }
    @ApiOperation("增加")
    @PostMapping("save")
    public Result save(@RequestBody ProcessType processType){
        oaProcessTypeService.save(processType);
        return Result.ok();
    }
    @ApiOperation("修改")
    @PutMapping("update")
    public Result update(@RequestBody ProcessType processType){
        oaProcessTypeService.updateById(processType);
        return Result.ok();
    }
    @ApiOperation("删除")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Integer id){
        oaProcessTypeService.removeById(id);
        return Result.ok();
    }
    @ApiOperation("获取所有审批类型")
    @GetMapping("getTypeList")
    public Result getTypeList(){
        List<ProcessType> list = oaProcessTypeService.list();
        return Result.ok(list);
    }
}
